﻿using System;
using Loki;

namespace Luna.UI.Users
{
    public class UserListViewModel : LunaViewModel
    {
        public LokiCollection<DisplayUser> Users { get; private set; }

        public UserListViewModel()
        {
            Users = CreateCollection<DisplayUser>();
            Users.TrackDeleted = false;
            Load += UserListViewModel_Load;
        }

        private void UserListViewModel_Load(object P_Sender, EventArgs e)
        {
            Users.Synchronize(
                ApplicationModel.Security.Users,
                (u, d) =>
                {
                    d.ID = u.ID;
                    d.Name = u.Name;
                    d.Login = u.Login;
                    d.Surname = u.Surname;
                },
                    (u, d) => d.ID == u.ID,
                    u => u.Name);
        }
    }
}
